package com.central.apps.handler.project;

import com.central.app.common.base.BaseHandler;
import com.central.app.service.HandlerService;
import com.central.apps.common.constant.BizConstant;
import com.central.apps.service.BudgetTempleteService;
import com.central.bizcommon.model.flow.FlowNode;
import com.central.bizcommon.model.flow.FlowOpinion;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 处理预算管理业务逻辑
 *
 * @author lidachao
 * @date 2023/3/22
 */
@Component
@Slf4j
public class ProjectCancelHandler extends BaseHandler {

    @Autowired
    private HandlerService handlerService;

    @Override
    public String beforeExcuteFlow(String app, Long id, FlowNode flowNode, FlowOpinion op) throws Exception {
        if("complete".equals(flowNode.getId())) {
            Integer proId = MapUtils.getInteger(op.getVariables(), "proid");
            // 更新项目台账状态
            handlerService.updateBySql("update gq_proaccount set prostatus = '已终止', proschedulestatus = null where id = " + proId);

            // 更新预算状态
            handlerService.updateBySql("update gq_probudget set status = '已终止' where status = '执行中' and proid = " + proId);

            // 更新计划状态
            handlerService.updateBySql("update gq_scheduleplantask set status = '已终止' where status != '已完成' and proid = " + proId);
            handlerService.updateBySql("update gq_mytask set status = '已终止' where status != '已完成' and proid = " + proId);

            // 更新资源状态
            handlerService.updateBySql("update gq_proresource set status = '停用' where status = '可用' and proid = " + proId);
        }
        return null;
    }
}
